<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=8">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="format-detection" content="telephone=no">
    <title>{$region['title']}</title>
    <style type="text/css">
    	#header {
    height: 42px;
    width: 100%;
    background: #48b54e;
    line-height: 42px;
    color: #fff;
    text-align: center;
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    -webkit-transition: -webkit-transform 350ms ease;
    -moz-transition: -moz-transform 350ms ease;
}

.header_div {
    width: 100%;
    display: box;
    display: -webkit-box;
    display: -moz-box;
    margin-top: 0;
    height: 100%;
}

#left_div {
    width: 30px;
    height: 42px;
    background: url({MODULE_URL}template/mobile/style/style1/static/image/arrow-r.png) center no-repeat;
    background-size: 18px;
    transform: rotate(180deg);
    -moz-transform: rotate(180deg);
    -webkit-transform: rotate(180deg);
}

#middle_div {
    -moz-box-flex: 1;
    -webkit-box-flex: 1;
}

#title {
    font-size: 20px;
    font-weight: bold;
}

#right_div {
    width: 50px;
    height: 42px;
}

.right_bottom {
    width: 50px;
    height: 42px;
    border-radius: 0px;
    transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -webkit-transition: all 0.5s ease-in-out 0;
    transform: scale(1.5, 1);
    -webkit-transform: scale(1.5, 1);
    -moz-transform: scale(1.5, 1);
}

.right_bottom_btn {
    border-radius: 23px;
    background: #005b8b;
    transform: scale(0.5, 1);
    -webkit-transform: scale(0.5, 1);
    -webkit-transform: scale(0.5, 1)
}

.right_img {
    background-size: 40px;
    width: 50px;
    height: 42px;
    position: absolute;
    z-index: 2;
    top: 0;
    right: 0;
    font-size: 16px
}
    </style>
    <link rel="stylesheet" type="text/css" href="{MODULE_URL}template/mobile/style/style1/static/css/confirm.css" />
    <script type="text/javascript" src="{$_W['siteroot']}app/resource/js/lib/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="{MODULE_URL}template/mobile/style/style1/static/js/jquery.confirm.js"></script>
</head>

<body class="bg-f2">
        <!-- 20150504-头部-start -->
        <!-- <header class="header" id="index-header">
            <a class="index-return"></a>
            <section class="header-title">购物车</section>
            <section class="header-operate" id="goodsDelete">编辑</section>
        </header> -->
        <!-- 20150504-头部-start -->
        <div class="index-top" style="margin-top:-16px;">
            <!-- 20150504-头部-start -->
            <header id="header">
                <div class="header_div">
                    <div id="left_div" onClick="javascript:history.back();"></div>
                    <div id="middle_div">
                        <h1 id="title">购物车</h1></div>
                    <div id="right_div">
                        <div class="right_bottom"></div>
                        <div class="right_img" id="goodsDelete" >编辑</div>
                    </div>
                </div>
            </header>
            <!-- 20150504-头部-start -->
        </div>
    <div class="hr-150-1"></div>
    <!-- 20150505-订单内容-start -->
    {loop $list $item}
    {php $price += $item['totalprice'];}
	{php $goods = $item['goods']}
    <section class="order-content">
        <input name="specGoodPk" type="hidden" value="954c47b7-db0c-4e32-8fd3-9e844a3553ea">
        <input name="goodPk" type="hidden" value="dea6f4f9-cba7-43c4-8d5b-c0501a9ba9b8">
        <article class="car-left">
            <label class="checkbox">
                <input type="checkbox" name="cartid" checked="checked" value="{$item['id']}" data-group="cartid" id="cartid">
                <i></i>
            </label>
        </article>
        <article class="car-rigth">
            <div class="order-img" onclick="javascript:window.location.href='{php echo $this->createMobileUrl('shopping',array('op' => 'detail','id' => $goods['id']))}'"><img src="{php echo tomedia($goods['thumb']);}" ></div>
            <div class="order-name car-name">
                <h3>
						[默认]{$goods['title']}
					</h3>
                <div class="pro-price car-price">
                    <span class="p-price-now car-price-now">
							<b>¥ 
								<c id="price">
										{$goods['marketprice']}
								</c>
							</b>
						</span>
                    <span class="p-price-cost">¥ {$goods['productprice']}</span>
                </div>
                <div class="option1">
                    <label class="btn-del" name="decrease" onclick="reduceNum({$item['id']})"></label>
                    <input type="tel" class="form-control input-sm pricetotal goodsnum" value="{$item['total']}" price="{$goods['marketprice']}" pricetotal="{$item['totalprice']}" id="goodsnum_{$item['id']}" cartid='{$item['id']}' />
                    <label class="btn-add" name="add" id="100.0" onclick="addNum({$item['id']})"></label>
                </div>
            </div>
            <div class="car-xj">
                小计：<b>￥<span class="singletotalprice" name="voorderSum">{$item['totalprice']}</span></b> （含运费：
                <b>￥<span id="" name="vologisticsSum">0.00</span></b>）
            </div>
        </article>
    </section>
    {php $n++;}
    {/loop}

    <footer class="order-footer">
        <article style="overflow:hidden">
            <label class="checkbox car-checkbox">
                <input type="checkbox" class="vam" id="selectBox" name="subBox" checked="checked" data-group="cartid">
                <i></i>
            </label>
            <label class="check-all" >全选</label>
            <label class="car-amount" id="showPrice">
                <p>合计：<span>¥<c id="pricetotal">{$price}</c></span></p>
            </label>
        </article>
        <a class="pro-footer-buy" id="deleteBtn" style="display:none;">确认删除</a>
        <a class="pro-footer-buy" id="submit" href="{php echo $this->createMobileUrl('shopping',array('op' => 'confirm'))}">结算</a>
    </footer>
    <!-- 20150505-底部-end -->
     <script type="text/javascript">
     //打开商品删除页面事件
	$("#goodsDelete").click(function(){
		showDeleteView();
	});
	function showDeleteView(){
		if($("#goodsDelete").html() == "完成"){
			$("#goodsDelete").html("编辑");
			$("[name='sopPkno']").attr("checked","checked");
			$("#selectBox").attr("checked","checked");
		}else{
			$("#goodsDelete").html("完成");
			$("[name='sopPkno']").attr("checked",null);
			$("#selectBox").attr("checked",null);
		}
		$("#submit").toggle();
		$("#showPrice").toggle();
		$("#deleteBtn").toggle();
	}
	//删除事件
		$("#deleteBtn").click(function(){
			var obj = $(this);
			//获取需要删除的购物车商品
			var sopPkno = getCheckedSopPknos();

			if(sopPkno == "")
				return false;

			var url = "{php echo $this->createMobileUrl('shopping',array('op'=>'mycart','operation'=>'remove'))}";

			var data = {cartids:sopPkno};
			$.confirm({
				'title'		: '提示对话框',
				'message'	: '您要删除购物车里的商品 <br />删除后将不会进行还原，请确定继续?',
				'buttons'	: {
					'确定'	: {
						'class'	: 'blue',
						'action': function(){
							// $.post(url,data,function(json){
							// 	if (json.result == 1) {
							// 		window.location.reload();
							// 	};
							// 	showMessage(json.message);
							// 	if(json.state != "2000")
							// 		return false;
							// 	/*删除删除已成功的商品*/
							// 	var obj = $("[name=goodsid]");
							// 	for(var i=0; i<obj.length; i++){
							// 		if($(obj[i]).attr("checked") != null){
							// 			$(obj[i]).parents("section").remove();
							// 		}
							// 	}
							// 	shopcart.showDeleteView();
							// 	changeBuyNum.totalNumber();
							// },"json");
							$.ajax({
									type:'post',
									url:url,
									data:data,
									dataType: "json",
									success:function(json){

											if (json.result == 1) {
												window.location.reload();
											};
									}

							});
						}
					},
					'取消'	: {
						'class'	: 'gray',
						'action': function(){}	// Nothing to do in this case. You can as well omit the action property.
					}
				}
			});
		});
	function getCheckedSopPknos(){
		var sopPknos = "";
		var checkedSopObj = $("[name='cartid']:checked");
		if(checkedSopObj.length==0)
			showMessage("请选择至少一件商品!");
		
		for(var i=0; i<checkedSopObj.length; i++){
			if(i>0)
				sopPknos+=",";
			sopPknos+=$(checkedSopObj[i]).val();
		}
		return sopPknos;
	}
     $(function() {
	    $("#selectBox").click(function() {

	        var checked = $(this).get(0).checked;
	        var group = $(this).data('group');
	        $("#cartid[data-group='" + group + "']").each(function() {
	            $(this).get(0).checked = checked;
	        })

	    });
	});

	function updateCart(id,num){
		var url = "{php echo $this->createMobileUrl('shopping',array('op'=>'mycart','operation'=>'update'), true)}"+ "&id=" + id+"&num=" + num;
		$.getJSON(url, function(s){
			if(s.result==1){
				// tip("只能购买 " + s.maxbuy + " 件!");
				window.location.reload();
				return;
			}
		});
	}
    function addNum(id){
		// var mb = maxbuy;
		 var stock =$("#stock_" + id).html()==''?-1:parseInt($("#stock_" + id).html());

				// if(mb>stock && stock!=-1){
				// 	mb = stock;
				// }
		var num = parseInt( $("#goodsnum_" + id).val() ) + 1;

		// if(num>mb && mb>0){
		// 	tip("最多只能购买 " + mb + " 件!",true);
		// 	return;
		// }
		$("#goodsnum_" + id).val(num);
		var price = parseFloat( $("#singleprice_"+id).html() ) * num;
		$("#goodsprice_" + id).html(price);
		canculate();
		var id = id;
		updateCart(id,num);
	}
	function reduceNum(id){
		var num = parseInt( $("#goodsnum_" + id).val() );
		if(num-1<=0){
			return;
		}
		num--;
		$("#goodsnum_" + id).val(num);
		var price = parseFloat( $("#singleprice_"+id).html() ) * num;
		$("#goodsprice_" + id).html(price);
		canculate();
		var id = id;
		updateCart(id,num);
	}
	function canculate(){
		var total = 0;
		$(".singletotalprice").each(function(){
			total+=parseFloat( $(this).html() );
		});

		$("#pricetotal").html(total);
	}

    </script>

</body>

</html>
